package com.xiguanlezz.cn.server;

import com.xiguanlezz.cn.UserService;
import com.xiguanlezz.cn.service.UserServiceImpl;
import org.apache.thrift.protocol.TJSONProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportException;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/10/27 21:40
 * @Description：单线程BIO服务端实现
 */
public class SimpleServer {
    public static void main(String[] args) throws TTransportException {
        // bind本地端口
        TServerTransport transport = new TServerSocket(8888);

        // 协议工厂（方法名、方法参数反序列化，响应结果序列化）
        TJSONProtocol.Factory protocolFactory = new TJSONProtocol.Factory();

        // 业务实现类
        UserService.Processor processor = new UserService.Processor(new UserServiceImpl());

        TServer.Args arg = new TServer
                .Args(transport)
                .protocolFactory(protocolFactory)
                .processor(processor);

        // 启动基于BIO的单线程服务器
        TSimpleServer simpleServer = new TSimpleServer(arg);
        simpleServer.serve();
    }
}
